<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%-- 
    JSP Name : cm_100_02.jsp
    Description : 커뮤니티 상세
    author EUNGA
    since 2012. 7. 25.
    version 1.0
    Modification Information
       since          author              description
    ===========    =============    ===========================
    2012. 7. 25.     EUNGA     최초 생성
--%>
<%@ include file="/WEB-INF/jsp/co/mn/include/declare.jspf" %>
<%@ include file="/WEB-INF/jsp/co/mn/include/session.jspf" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/WEB-INF/jsp/co/mn/include/header.jspf" %>
<script type="text/javaScript" language="javascript">
$(document).ready(function() {    
    /* form validation check */
    onloadCharCheck();
    
    selectCmtList();
    
    /* List Page 이동 */
    $("#listButn").bind("click", moveListPage);
    /* Form Submit */
    $("#mdfyButn").bind("click", mdfySubm);
    /* Form Submit */
    $("#rpReButn").bind("click", rpReButn);
});

/*
 * 리스트페이지 이동
 */
function moveListPage() {
    $("#mainForm").attr('action','/cm_100_01.do').submit();
}
  
/*
 * 수정 페이지로 이동
 */
function mdfySubm() {
    $("#mainForm").attr('action','/cm_100_03.do').submit();
}

/*
 * 덧글 입력
 */
function rpReButn(glfdIdx) {
    var submitUrl = "/cm_100_08.do";
    var sbcTxt = "";
    var param = "";
    if(glfdIdx == 0){ // 덧글인 경우
        sbcTxt = encodeURIComponent(encodeURIComponent($("#cmtSbc").val()));
        if(sbcTxt == "" || sbcTxt == null){
            alert("내용을 입력 하세요.");
            return;
        }
        param = "sbc=" + sbcTxt + "&blbIdx=" + $("#blbIdx").val();
        
        $("#sbc").val($("#cmtSbc").val());
        $("#dept").val(0);
    }else{ // 답글인경우
        sbcTxt = encodeURIComponent(encodeURIComponent($("#cmtSbc_" + glfdIdx).val()));
        if(sbcTxt == "" || sbcTxt == null){
            alert("내용을 입력 하세요.");
            return;
        }
        param = "sbc=" + sbcTxt + "&blbIdx=" + $("#blbIdx").val() + "&glfdIdx=" + glfdIdx + "&dept=1";
        
        $("#sbc").val($("#cmtSbc_" + glfdIdx).val());
        $("#glfdIdx").val(glfdIdx);
        $("#dept").val(1);
    }
    
    $("#replyForm").attr('target','relplyFrame');
    $("#replyForm").attr('action', submitUrl);
    $("#replyForm").submit();
    
    //ajaxSubmit(submitUrl,param,selectCmtList) ;
}

/* textarea form */
function cmtForm(glfdIdx){
    $("#cmtInput_" + glfdIdx).toggle();
    $("#CmtText_" + glfdIdx).text($("#CmtText_" + glfdIdx).text() == "답글달기" ? "답글취소" : "답글달기");
}

/* textarea form */
function cmtDel(cmtIdx){
    var submitUrl = "/cm_100_10.do";
    var param = "cmtIdx=" + cmtIdx;
    if(confirm("삭제 하시겟습니까?")){
        ajaxSubmit(submitUrl,param,selectCmtList) ;
    }
}

/*
 * 덧글 조회
 */
function selectCmtList() {
    var submitUrl = "/cm_100_09.do";
    var param = "blbIdx=" +$("#blbIdx").val();
    ajaxSubmit(submitUrl,param,rpList) ;
}

/*
 * 덧글 리스트 작성
 */
function rpList(jsonData) {
    
    var html = "";
    var totalCnt = "0";
    var evalData = eval(jsonData);
    if (jsonData != null) {
        totalCnt = evalData.jsonArray.length;
    }
    
    var htmlTxt = "<div class='commentFrm'><textarea rows='2' cols='85' id='cmtSbc' name='cmtSbc'></textarea>";
        htmlTxt = htmlTxt +  "<input id='rpReButn' name='rpReButn' onClick='rpReButn(0)' type='image' src='/img/mng/btn/btn_comment.gif' alt='댓글작성' title='댓글작성' /></div>";
        htmlTxt = htmlTxt +  "<div class='commentArea'>";
        htmlTxt = htmlTxt +  "<p class='commentNo'>댓글 "+ totalCnt +"개</p>";
        if (jsonData != null && (evalData.jsonArray.length > 0 || evalData.jsonArray != null)) {
            for (var i = 0; i < evalData.jsonArray.length; i++) {
                if(evalData.jsonArray[i].dept == 0 ){
                    htmlTxt = htmlTxt + "<div class='commentView'>";
                }else{
                    htmlTxt = htmlTxt + "<div class='commentView reply'>";
                }
                htmlTxt = htmlTxt + "<p class='userInfo'><strong>" + evalData.jsonArray[i].pprrNm + "</strong><span>" + evalData.jsonArray[i].rgstDt + "</span></p>";
                htmlTxt = htmlTxt + "<p class='comment'>" + evalData.jsonArray[i].sbc + "</p>";
                if(evalData.jsonArray[i].dept == 0 ){
                    htmlTxt = htmlTxt + "<div class='btnCmt'><button id='CmtText_" + evalData.jsonArray[i].glfdIdx + "' type='button' onClick='cmtForm(" + evalData.jsonArray[i].glfdIdx + ")'>답글달기</button>&#124;<input onClick='cmtDel(" + evalData.jsonArray[i].cmtIdx + ")' type='submit' value='삭제' title='삭제' /></div>";
                    htmlTxt = htmlTxt + "<div id='cmtInput_" + evalData.jsonArray[i].glfdIdx + "' class='commentFrm'>";
                    htmlTxt = htmlTxt + "<textarea id='cmtSbc_" + evalData.jsonArray[i].glfdIdx + "' rows='2' cols='85'></textarea><input type='image' onClick='rpReButn("+evalData.jsonArray[i].glfdIdx+")' src='/img/mng/btn/btn_comment.gif' alt='댓글작성' title='댓글작성' /></div>";
                }else{
                    htmlTxt = htmlTxt + "<div class='btnCmt'><input type='submit' onClick='cmtDel(" + evalData.jsonArray[i].cmtIdx + ")' value='삭제' title='삭제' /></div>";
                }
                
                htmlTxt = htmlTxt + "</div>";
                
            }
        }
        htmlTxt = htmlTxt +  "</div>";
        
    $("#comment").html(htmlTxt);
}
</script>
</head>
<body>
<div id="wrap">
    <!-- top -->
    <%@ include file="/WEB-INF/jsp/co/mn/include/top.jsp" %>
    <!-- top -->
 
    <!-- container -->
    <div id="container">
        <!-- LNB -->
        <%@ include file="/WEB-INF/jsp/co/mn/include/left.jsp" %>
        <!-- LNB -->
        <div id="contents">
            <!-- location -->
            <%@ include file="/WEB-INF/jsp/co/mn/include/location.jsp" %>
            <!-- location -->
            <form id="replyForm" name="replyForm" method="post">
                <input type="hidden" id="sbc" name="sbc" value="" />
                <input type="hidden" id="glfdIdx" name="glfdIdx" value="" />
                <input type="hidden" id="blbIdx" name="blbIdx" value="${result.blbIdx }" />
                <input type="hidden" id="dept" name="dept" value="" />
            </form>
            <form id="mainForm" name="mainForm" method="post">
                <input type="hidden" id="currentPageNo" name="currentPageNo" value="${rqInfo.currentPageNo }" />
                <input type="hidden" id="srchScn" name="srchScn" value="${rqInfo.srchScn }" />
                <input type="hidden" id="srchTxt" name="srchTxt" value="${rqInfo.srchTxt }" />
                <input type="hidden" id="blbIdx" name="blbIdx" value="${result.blbIdx }" />
            <table border="1" class="modTable" summary="커뮤니티 관리 표">
                <col width="25%" />
                <col width="25%" />
                <col width="25%" />
                <col width="25%" />
                <tbody>
                    <tr>
                        <th>이름</th>
                        <td>${result.pprrNm }</td>
                        <td class="subThead">기관명</td>
                        <td>${result.instNm }</td>
                    </tr>
                    <tr>
                        <th>등록일</th>
                        <td>${result.rgstDt }</td>
                        <td class="subThead">조회수</td>
                        <td>${result.iqNo }</td>
                    </tr>
                    <tr>
                        <th class="subThead">정열순서</th>
                        <td colspan="3">
                        	<c:if test="${result.sortNum < 1 }">우선노출</c:if>
                        	<c:if test="${result.sortNum ==1 }">일반노출</c:if>
                        </td>
                    </tr>
                    <tr>
                        <th>제목</th>
                        <td colspan="3">${result.titl}</td>
                    </tr>
                    <tr>
                        <th>첨부파일</th>
                        <td colspan="3"><a href="#" onclick="getUpFileDownload('0050','${result.blbIdx}');return false;">${result.filNm }</a></td>
                    </tr>
                    <tr>
                        <th>내용</th>
                        <td colspan="3" class="viewTdata">
                           <c:if test="${result.thumnImgPath == 'image'}">
                                <img src="/upfile/image/${result.thumnImgNm }" alt="" />
                           </c:if>
                            ${result.sbc}
                        </td> 
                    </tr>
                </tbody>
            </table>
            </form>
            <div id="comment" name="comment" class="commentWrap">
                <div class="commentArea">
                </div>
            </div>
            <div class="btnBoard">
                <span class="reverse">
                    <input type="submit" title="수정" id="mdfyButn" name="mdfyButn" value="수정" />
                    <input type="submit" id="listButn" name="listButn" title="목록" value="목록" />
                </span>
            </div>
        </div>
    </div>
    <!-- /container -->
 
    <!-- footer -->
    <%@ include file="/WEB-INF/jsp/co/mn/include/bottom.jsp" %>
    <!-- /footer -->
    <iframe id="relplyFrame" name="relplyFrame" frameborder="0" height="0" width="0"></iframe>
</div>
</body>
</html>